package com.mall.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

@SuppressWarnings("serial")
public class YNSelect extends TagSupport
{
	private String value;
	private String id;
	private String className;
	private String name;
	private String extend;
	private String disabled;
	

	public String getValue()
	{
		return value;
	}


	public void setValue(String value)
	{
		this.value = value;
	}


	public String getId()
	{
		return id;
	}


	public void setId(String id)
	{
		this.id = id;
	}


	public String getClassName()
	{
		return className;
	}


	public void setClassName(String className)
	{
		this.className = className;
	}


	public String getName()
	{
		return name;
	}


	public void setName(String name)
	{
		this.name = name;
	}


	public String getExtend()
	{
		return extend;
	}


	public void setExtend(String extend)
	{
		this.extend = extend;
	}


	@Override
	public int doStartTag() throws JspException
	{
		// TODO Auto-generated method stub
		try
		{
			JspWriter out = pageContext.getOut();
			
			String tempString = "<select ${id} ${name} ${className} ${disabled} ${extend}><option value=\"Y\" ${YSelected}>是</option><option value=\"N\" ${NSelected}>否</option></select>";
			tempString = (id==null?tempString.replaceAll("\\$\\{id\\}", ""):tempString.replaceAll("\\$\\{id\\}", "id="+id));
			tempString = (name==null?tempString.replaceAll("\\$\\{name\\}", ""):tempString.replaceAll("\\$\\{name\\}", "name="+name));
			tempString = (className==null?tempString.replaceAll("\\$\\{className\\}", ""):tempString.replaceAll("\\$\\{className\\}", "class="+className));
			tempString = ((disabled==null||!disabled.equals("Y")) ?tempString.replaceAll("\\$\\{disabled\\}", ""):tempString.replaceAll("\\$\\{disabled\\}", "disabled=\"disabled\""));
			tempString = (extend==null?tempString.replaceAll("\\$\\{extend\\}", ""):tempString.replaceAll("\\$\\{extend\\}", extend));
			tempString = ((value==null || !value.equals("N")) ? tempString.replaceAll("\\$\\{YSelected\\}", "selected=\"selected\"").replaceAll("\\$\\{NSelected\\}", ""): tempString.replaceAll("\\$\\{YSelected\\}", "").replaceAll("\\$\\{NSelected\\}","selected=\"selected\""));
			out.print(tempString);
			out.flush();
		}
		catch (Exception e)
		{
			// TODO: handle exception
			e.printStackTrace();
			
			throw new JspTagException(e.getMessage());
		}
		
		return SKIP_BODY;
	}


	public String getDisabled() {
		return disabled;
	}


	public void setDisabled(String disabled) {
		this.disabled = disabled;
	}

}
